﻿using MyFurion.Application;
using Furion.EventBus;

namespace MyFurion.Start
{
    /// <summary>
    /// 日志事件订阅依赖接口
    /// </summary>
    public class LogEventSubscriber : IEventSubscriber
    {
        /// <summary>
        /// 请求日志
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        [EventSubscribe("Add:RequestLog")]
        public async Task AddWorkLog(EventHandlerExecutingContext context)
        {
            var log = (RequestLog)context.Source.Payload;
            await App.GetService<RequestLogRepository>().Add(log);
        }
        /// <summary>
        /// 错误日志
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        [EventSubscribe("Add:ErrorLog")]
        public async Task AddErrorLog(EventHandlerExecutingContext context)
        {
            var log = (ErrorLog)context.Source.Payload;
            await App.GetService<ErrorLogRepository>().Add(log);
        }
    }
}
